package com.bupt.smart.ui.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bupt.smart.model.Delivery;
import com.bupt.smart.smart.R;

import java.util.List;

/**
 * Created by ght on 2016/6/20.
 */
public class DeliveryRecyclerViewAdapter extends RecyclerView.Adapter<DeliveryRecyclerViewAdapter.DeliveryViewHolder> {
    private Context mContext;
    private List<Delivery> mData;

    public DeliveryRecyclerViewAdapter(Context context, List<Delivery> datas) {
        this.mContext = context;
        mData = datas;
    }

    @Override
    public DeliveryViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.delivery_recyclerview_item, parent, false);

        return new DeliveryViewHolder(view);
    }

    @Override
    public void onBindViewHolder(DeliveryViewHolder holder, int position) {
        holder.consignee.setText(mData.get(position).getUserName());
        holder.company.setText(mData.get(position).getDeliveryCom());
        holder.date.setText(mData.get(position).getDate());
        holder.extraInfo.setText(mData.get(position).getExtraInfo());
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

    public class DeliveryViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{
        TextView consignee; //收货人
        TextView company; //快递公司
        TextView date; //入库时间
        TextView extraInfo; //备注信息

        public DeliveryViewHolder(View v) {
            super(v);
            consignee = (TextView) v.findViewById(R.id.delivery_rv_item_username);
            company = (TextView) v.findViewById(R.id.delivery_rv_item_company);
            date = (TextView) v.findViewById(R.id.delivery_rv_item_date);
            extraInfo = (TextView) v.findViewById(R.id.delivery_rv_item_extra_info);
            v.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            int itemPosition = getAdapterPosition();
        }
    }
}
